package com.hnkywl.sts.entity.xsgl;

import com.hnkywl.sts.entity.BaseEntity;
import com.hnkywl.sts.entity.base.Sjzdz;
import com.hnkywl.sts.entity.cggl.Jsd;
import com.hnkywl.sts.entity.cggl.Glfy;
import com.hnkywl.sts.entity.htgl.Xsht;
import com.hnkywl.sts.entity.organ.*;
import com.hnkywl.sts.entity.sfgl.Sfk;
import com.hnkywl.sts.entity.sys.Yg;
import org.hibernate.annotations.*;

import javax.persistence.*;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;
import java.util.List;

/**
 * 说明：销售单
 * 包:        com.hnkywl.sts.entity.xsgl
 * 类描述:    销售单
 * 修改备注: [说明本次修改内容]
 * 版本:        [v1.0]
 */
@Entity
@Table(name = "T_BIZ_XSD")
@Where(clause = "deleted!='1'")
public class Xsd extends BaseEntity {
    @Id
    @SequenceGenerator(name = "seqXsd", allocationSize = 1, sequenceName = "SEQ_BIZ_XSD")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seqXsd")
    private Long id;

    /**
     * 订单ID（交易系统）
     */
    private String orderId;

    /**
     * 销售单号
     */
    private String xsdh;

    /**
     * 销售类型(库存销售 kcls，直达到货 zddh，合同销售 htxs,保供销售 bgxs，内部销售 nbxs)
     */
    private String xslx;


    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "LJ_ID")
    @NotFound(action = NotFoundAction.IGNORE)
    private Lj lj;

    /**
     * 客户
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "KH_ID")
    @NotFound(action = NotFoundAction.IGNORE)
    private Gsjg kh;

    /**
     * 客户部门（内部销售单客户为内部公司时）
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "KHBM_ID")
    private Gsjg khbm;

    /**
     * 销售合同
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "XSHT_ID")
    @NotFound(action = NotFoundAction.IGNORE)
    private Xsht xsht;

    /**
     * 工程
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "GC_ID")
    @NotFound(action = NotFoundAction.IGNORE)
    private Gc gc;

    /**
     * 提货仓库
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "CK_ID")
    @NotFound(action = NotFoundAction.IGNORE)
    private Ck thck;

    //销售结算单
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "XSJSD_ID")
    private Jsd xsjsd;
    /**
     * 是否支付吊费
     */
    private Boolean sfzfdf;

    /**
     * 是否可多次提货(限自提)
     */
    private Boolean sfkdcth;

    /**
     * 销售时间
     */
    private Date sxsj;

    /**
     * 出库时间
     */
    private Date cksj;

    /**
     * 审核时间
     */
    private Date shsj;

    /**
     * 税率
     */
    private Double sl;

    /**
     * 发货时间
     */
    private Date fhsj;

    /**
     * 发运责任
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "FYZR_SJZDZ_ID")
    private Sjzdz fyzr;

    /**
     * 放货方式 （self自提 transfer过户）
     */
    private String fhfs;

    /**
     * 代收运费金额
     */
    private Double dsyfje = 0d;

    /**
     * 交货时间
     */
    private Date jhsj;

    /**
     * 交货地址
     */
    private String jhdz;

    /**
     * 收货人
     */
    private String shry;

    /**
     * 收货人电话
     */
    private String shrdh;

    /**
     * 交货要求
     */
    private String jhyq;

    /**
     * 备注
     */
    private String bz;

    /**
     * 提货人
     */
    private String thr;

    /**
     * 申报公司
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "SBGS_ID")
    private Gsjg sbgs;

    /**
     * 申报部门
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "SBBM_ID")
    private Gsjg sbbm;

    /**
     * 申报人
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "SBR_ID")
    private Yg sbr;

    /**
     * 销售公司
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "XSGS_ID")
    private Gsjg xsgs;

    /**
     * 销售部门
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "XSBM_ID")
    private Gsjg xsbm;

    /**
     * 销售人
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "XSR_ID")
    private Yg xsr;
    /**
     * 出库人
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "CKR_ID")
    private Yg ckr;


    /**
     * 销售单审核
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "SHR_ID")
    private Yg shr;

    /**
     * 协办公司
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "XBGS_ID")
    private Nbgs xbgs;

    /**
     * 协办部门
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "XBBM_ID")
    private Nbbm xbbm;

    /**
     * 状态  ybc:已保存,ysh:已审核,ygk:已挂款,ytj:出库金额审核，ysp：已出库，ypk：已配款
     */
    private String zt;

    /**
     * 调整申请状态  wsq，ysq，ysp
     */
    private String tzsqzt;

    /**
     * 是否内部
     */
    private Boolean sfnb = false;

    /**
     * 财务审核
     */
    private Boolean cwsh = false;

    /**
     * 已审核
     */
    private Boolean ysh = false;

    /**
     * 已出库
     */
    private Boolean yck = false;

    /**
     * 已结算
     */
    private Boolean yjs = false;

    /**
     * 销售明细
     */
    @OneToMany(fetch = FetchType.LAZY, targetEntity = Xsmx.class)
    @Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE})
    @JoinColumn(name = "XSD_ID")
    @Where(clause = "deleted!='1'")
    private List<Xsmx> xsmxList;

    @OneToMany(fetch = FetchType.LAZY, targetEntity = Glfy.class)
    @Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE})
    @JoinColumn(name = "XSD_ID")
    @Where(clause = "deleted!='1'")
    private List<Glfy> xsfyList;

    @OneToMany(fetch = FetchType.LAZY, targetEntity = Sfk.class)
    @Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE})
    @JoinColumn(name = "XSD_ID")
    @Where(clause = "deleted!='1'")
    private List<Sfk> skList;

    //配送单
    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "PSD_ID")
    private Psd psd;

    /**
     * 已配送
     */
    private Boolean yps = false;

    /**
     * 是否红冲
     */
    private Boolean sftzd = false;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "YXSD_ID")
    @NotFound(action = NotFoundAction.IGNORE)
    private Xsd yxsd;
    //出库审核标志
    private Boolean ckshbz = false;

    /**
     * 操作状态
     */
    @Transient
    private String czzt;

    @Formula("(select sum(t.ck_sbsl) from T_BIZ_XSMX t where t.XSD_ID=ID and DELETED!=1)")
    private Double cksl;

    @Formula("(select sum(t.SBSL) from T_BIZ_XSMX t where t.XSD_ID=ID and DELETED!=1)")
    private Double xssl;

    @Formula("(select sum(t.js) from T_BIZ_XSMX t where t.XSD_ID=ID and DELETED!=1)")
    private Double xsjs;

    @Formula("(select sum(decode(nvl(t.sjdj,0),0,t.HSJ,t.sjdj)*t.sbsl) from T_BIZ_XSMX t where t.XSD_ID=ID and DELETED!=1)")
    private Double xsje;

    @Formula("(select sum(t.HSJ*t.SBSL) from T_BIZ_XSMX t where t.XSD_ID=ID and DELETED!=1)")
    private Double hszje;

    @Formula("(select sum(t.BHSJ*t.ck_sbsl) from T_BIZ_XSMX t where t.XSD_ID=ID and DELETED!=1)")
    private Double xsbhsje;
    //赎货总金额
    @Formula("(select Round(sum(nvl(t.SJDJ,0)*t.ck_sbsl),2) from T_BIZ_XSMX t where t.XSD_ID=ID and DELETED!=1)")
    private Double shzje;

    @Formula("(select sum(t.JE) from T_BIZ_GLFY t where t.XSD_ID=ID and DELETED!=1)")
    private Double glfyje;

    // 是否已经付款完成,1：付款已完成，0和空：付款未完成
    private String sfyfk;

    // 已付款时间
    private Date yfksj;

    //接口生成销售单
    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "BCXSD_ID")
    @NotFound(action = NotFoundAction.IGNORE)
    private Xsd bcxsd;

    public Xsd getBcxsd() {
        return bcxsd;
    }

    public void setBcxsd(Xsd bcxsd) {
        this.bcxsd = bcxsd;
    }

    /**
     * 关联ID
     */
    private Long glId;

    /**
     * 会计年
     */
    @Column(name = "jiuqi_acctyear")
    private Integer acctyear;
    /**
     * 生成久其凭证时提供的ID
     */
    @Column(name = "jiuqi_uuid")
    private String uuid;
    /**
     * 久其返回的凭证ID
     */
    @Column(name = "jiuqi_voucher_id")
    private String voucherId;
    /**
     * 久其返回的凭证号
     */
    @Column(name = "jiuqi_voucher_num")
    private Integer voucherNum;
    /**
     * “久其插入标示”代码   1=未导入,2=导入开始,3=导入成功
     */
    @Column(name = "jiuqi_insert_flag")
    private Integer insertFlag = 1;
    /**
     * "久其删除标示”代码   1=未删除,2=删除开始,3=删除成功
     */
    @Column(name = "jiuqi_delete_flag")
    private Integer deleteFlag = 1;

    private Date drrq;

    //是否最后一次赎货
    private String endFlag;

    // 字号
    private String zh;

    // 打印提货人
    private String thrs;

    // 打印经办人
    private String jbr;

    // 打印身份证号码
    private String sfzhm;

    // 打印车号
    private String cars;

    // 流水号
    private String lsh;

    // 年
    private String year;

    // 月
    private String month;

    // 日
    private String day;

    // 挂款审核 0:不通过；，1：通过
    private String gksh;

    // 挂款审核人
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "GKSHR_ID")
    private Yg gkshr;

    // 审核时间
    private Date gkshsj;

    @Formula("(select sum(t.zjfpje) from T_BIZ_JFMX t where t.XSD_ID=ID)")
    private Double zjfpzje;

    public Double getZjfpzje() {
        return zjfpzje;
    }

    public void setZjfpzje(Double zjfpzje) {
        this.zjfpzje = zjfpzje;
    }

    public String getGksh() {
        return gksh;
    }

    public void setGksh(String gksh) {
        this.gksh = gksh;
    }

    public Yg getGkshr() {
        return gkshr;
    }

    public void setGkshr(Yg gkshr) {
        this.gkshr = gkshr;
    }

    public Date getGkshsj() {
        return gkshsj;
    }

    public void setGkshsj(Date gkshsj) {
        this.gkshsj = gkshsj;
    }

    public String getLsh() {
        return lsh;
    }

    public void setLsh(String lsh) {
        this.lsh = lsh;
    }

    public String getCars() {
        return cars;
    }

    public void setCars(String cars) {
        this.cars = cars;
    }

    public String getSfzhm() {
        return sfzhm;
    }

    public void setSfzhm(String sfzhm) {
        this.sfzhm = sfzhm;
    }

    public String getJbr() {
        return jbr;
    }

    public void setJbr(String jbr) {
        this.jbr = jbr;
    }

    public String getThrs() {
        return thrs;
    }

    public void setThrs(String thrs) {
        this.thrs = thrs;
    }

    public List<Sfk> getSkList() {
        return skList;
    }

    public void setSkList(List<Sfk> skList) {
        this.skList = skList;
    }

    public Double getShzje() {
        return shzje;
    }

    public void setShzje(Double shzje) {
        this.shzje = shzje;
    }

    public String getEndFlag() {
        return endFlag;
    }

    public void setEndFlag(String endFlag) {
        this.endFlag = endFlag;
    }

    public Double getHszje() {
        return hszje;
    }

    public void setHszje(Double hszje) {
        this.hszje = hszje;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Boolean getYps() {
        return yps;
    }

    public void setYps(Boolean yps) {
        this.yps = yps;
    }

    public String getXsdh() {
        return xsdh;
    }

    public void setXsdh(String xsdh) {
        this.xsdh = xsdh;
    }

    public String getXslx() {
        return xslx;
    }

    public void setXslx(String xslx) {
        this.xslx = xslx;
    }

    public Lj getLj() {
        return lj;
    }

    public void setLj(Lj lj) {
        this.lj = lj;
    }

    public Gsjg getKh() {
        return kh;
    }

    public void setKh(Gsjg kh) {
        this.kh = kh;
    }

    public Gsjg getKhbm() {
        return khbm;
    }

    public void setKhbm(Gsjg khbm) {
        this.khbm = khbm;
    }

    public Xsht getXsht() {
        return xsht;
    }

    public void setXsht(Xsht xsht) {
        this.xsht = xsht;
    }

    public Gc getGc() {
        return gc;
    }

    public void setGc(Gc gc) {
        this.gc = gc;
    }

    public Ck getThck() {
        return thck;
    }

    public void setThck(Ck thck) {
        this.thck = thck;
    }

    public Jsd getXsjsd() {
        return xsjsd;
    }

    public void setXsjsd(Jsd xsjsd) {
        this.xsjsd = xsjsd;
    }

    public Boolean getSfzfdf() {
        return sfzfdf;
    }

    public void setSfzfdf(Boolean sfzfdf) {
        this.sfzfdf = sfzfdf;
    }

    public Boolean getSfkdcth() {
        return sfkdcth;
    }

    public void setSfkdcth(Boolean sfkdcth) {
        this.sfkdcth = sfkdcth;
    }

    public Date getSxsj() {
        return sxsj;
    }

    public void setSxsj(Date sxsj) {
        this.sxsj = sxsj;
    }

    public Date getCksj() {
        return cksj;
    }

    public void setCksj(Date cksj) {
        this.cksj = cksj;
    }

    public Double getSl() {
        return sl;
    }

    public void setSl(Double sl) {
        this.sl = sl;
    }

    public Date getFhsj() {
        return fhsj;
    }

    public void setFhsj(Date fhsj) {
        this.fhsj = fhsj;
    }

    public Sjzdz getFyzr() {
        return fyzr;
    }

    public void setFyzr(Sjzdz fyzr) {
        this.fyzr = fyzr;
    }

    public Double getDsyfje() {
        return dsyfje;
    }

    public void setDsyfje(Double dsyfje) {
        this.dsyfje = dsyfje;
    }

    public Date getJhsj() {
        return jhsj;
    }

    public void setJhsj(Date jhsj) {
        this.jhsj = jhsj;
    }

    public String getJhdz() {
        return jhdz;
    }

    public void setJhdz(String jhdz) {
        this.jhdz = jhdz;
    }

    public String getShry() {
        return shry;
    }

    public void setShry(String shry) {
        this.shry = shry;
    }

    public String getShrdh() {
        return shrdh;
    }

    public void setShrdh(String shrdh) {
        this.shrdh = shrdh;
    }

    public String getJhyq() {
        return jhyq;
    }

    public void setJhyq(String jhyq) {
        this.jhyq = jhyq;
    }

    public String getBz() {
        return bz;
    }

    public void setBz(String bz) {
        this.bz = bz;
    }

    public String getThr() {
        return thr;
    }

    public void setThr(String thr) {
        this.thr = thr;
    }

    public Gsjg getSbgs() {
        return sbgs;
    }

    public void setSbgs(Gsjg sbgs) {
        this.sbgs = sbgs;
    }

    public Gsjg getSbbm() {
        return sbbm;
    }

    public void setSbbm(Gsjg sbbm) {
        this.sbbm = sbbm;
    }

    public Yg getSbr() {
        return sbr;
    }

    public void setSbr(Yg sbr) {
        this.sbr = sbr;
    }

    public String getFhfs() {
        return fhfs;
    }

    public void setFhfs(String fhfs) {
        this.fhfs = fhfs;
    }

    public Gsjg getXsgs() {
        return xsgs;
    }

    public void setXsgs(Gsjg xsgs) {
        this.xsgs = xsgs;
    }

    public Gsjg getXsbm() {
        return xsbm;
    }

    public void setXsbm(Gsjg xsbm) {
        this.xsbm = xsbm;
    }

    public Yg getXsr() {
        return xsr;
    }

    public void setXsr(Yg xsr) {
        this.xsr = xsr;
    }

    public Nbgs getXbgs() {
        return xbgs;
    }

    public void setXbgs(Nbgs xbgs) {
        this.xbgs = xbgs;
    }

    public Nbbm getXbbm() {
        return xbbm;
    }

    public void setXbbm(Nbbm xbbm) {
        this.xbbm = xbbm;
    }

    public String getZt() {
        return zt;
    }

    public void setZt(String zt) {
        this.zt = zt;
    }

    public String getTzsqzt() {
        return tzsqzt;
    }

    public void setTzsqzt(String tzsqzt) {
        this.tzsqzt = tzsqzt;
    }

    public Boolean getSfnb() {
        return sfnb;
    }

    public void setSfnb(Boolean sfnb) {
        this.sfnb = sfnb;
    }

    public Boolean getYsh() {
        return ysh;
    }

    public void setYsh(Boolean ysh) {
        this.ysh = ysh;
    }

    public Boolean getYck() {
        return yck;
    }

    public void setYck(Boolean yck) {
        this.yck = yck;
    }

    public Boolean getYjs() {
        return yjs;
    }

    public void setYjs(Boolean yjs) {
        this.yjs = yjs;
    }

    public List<Xsmx> getXsmxList() {
        return xsmxList;
    }

    public void setXsmxList(List<Xsmx> xsmxList) {
        this.xsmxList = xsmxList;
    }

    public List<Glfy> getXsfyList() {
        return xsfyList;
    }

    public void setXsfyList(List<Glfy> xsfyList) {
        this.xsfyList = xsfyList;
    }

    public Psd getPsd() {
        return psd;
    }

    public void setPsd(Psd psd) {
        this.psd = psd;
    }

    public Boolean getSftzd() {
        return sftzd;
    }

    public void setSftzd(Boolean sftzd) {
        this.sftzd = sftzd;
    }

    public Xsd getYxsd() {
        return yxsd;
    }

    public void setYxsd(Xsd yxsd) {
        this.yxsd = yxsd;
    }

    public Boolean getCkshbz() {
        return ckshbz;
    }

    public void setCkshbz(Boolean ckshbz) {
        this.ckshbz = ckshbz;
    }

    public Double getXssl() {
        return xssl;
    }

    public void setXssl(Double xssl) {
        this.xssl = xssl;
    }

    public Double getXsje() {
        return xsje;
    }

    public void setXsje(Double xsje) {
        this.xsje = xsje;
    }

    public String getOrderId() {
        return orderId;
    }

    public void setOrderId(String orderId) {
        this.orderId = orderId;
    }

    public Double getXsbhsje() {
        return xsbhsje;
    }

    public void setXsbhsje(Double xsbhsje) {
        this.xsbhsje = xsbhsje;
    }

    public Double getGlfyje() {
        return glfyje;
    }

    public void setGlfyje(Double glfyje) {
        this.glfyje = glfyje;
    }

    public String getSfyfk() {
        return sfyfk;
    }

    public void setSfyfk(String sfyfk) {
        this.sfyfk = sfyfk;
    }

    public Date getYfksj() {
        return yfksj;
    }

    public void setYfksj(Date yfksj) {
        this.yfksj = yfksj;
    }

    public Long getGlId() {
        return glId;
    }

    public void setGlId(Long glId) {
        this.glId = glId;
    }

    public Yg getCkr() {
        return ckr;
    }

    public void setCkr(Yg ckr) {
        this.ckr = ckr;
    }

    public Date getShsj() {
        return shsj;
    }

    public void setShsj(Date shsj) {
        this.shsj = shsj;
    }

    public Yg getShr() {
        return shr;
    }

    public void setShr(Yg shr) {
        this.shr = shr;
    }

    public Boolean getCwsh() {
        return cwsh;
    }

    public void setCwsh(Boolean cwsh) {
        this.cwsh = cwsh;
    }

    public Double getCksl() {
        return cksl;
    }

    public void setCksl(Double cksl) {
        this.cksl = cksl;
    }

    public Double getXsjs() {
        return xsjs;
    }

    public void setXsjs(Double xsjs) {
        this.xsjs = xsjs;
    }

    public String getCzzt() {
        return czzt;
    }

    public void setCzzt(String czzt) {
        this.czzt = czzt;
    }

    public Integer getAcctyear() {
        return acctyear;
    }

    public void setAcctyear(Integer acctyear) {
        this.acctyear = acctyear;
    }

    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public String getVoucherId() {
        return voucherId;
    }

    public void setVoucherId(String voucherId) {
        this.voucherId = voucherId;
    }

    public Integer getVoucherNum() {
        return voucherNum;
    }

    public void setVoucherNum(Integer voucherNum) {
        this.voucherNum = voucherNum;
    }

    public Integer getInsertFlag() {
        return insertFlag;
    }

    public void setInsertFlag(Integer insertFlag) {
        this.insertFlag = insertFlag;
    }

    public Integer getDeleteFlag() {
        return deleteFlag;
    }

    public void setDeleteFlag(Integer deleteFlag) {
        this.deleteFlag = deleteFlag;
    }

    public Date getDrrq() {
        return drrq;
    }

    public void setDrrq(Date drrq) {
        this.drrq = drrq;
    }

    public String getYear() {
        return year;
    }

    public void setYear(String year) {
        this.year = year;
    }

    public String getMonth() {
        return month;
    }

    public void setMonth(String month) {
        this.month = month;
    }

    public String getDay() {
        return day;
    }

    public void setDay(String day) {
        this.day = day;
    }

    public String getZh() {
        return zh;
    }

    public void setZh(String zh) {
        this.zh = zh;
    }
}
